/*
 * BncsMessageFactory.h
 *
 *  Created on: Nov 20, 2008
 *      Author: nathan
 *
 *  Provides a factory that creates BncsMessage instances
 *  from instances.
 */

#ifndef BNCSMESSAGEFACTORY_H_
#define BNCSMESSAGEFACTORY_H_

#define BNCS_MESSAGE_REGISTER(cls_name, id_num) \
	public: static int id = (id_num); \
	private: static BncsMessageFactoryRegistrar reg (id, new cls_name())

/* Registers a BncsMessage object with the BncsMessageFactory at
 * static initialization.
 */
class BncsMessageFactoryRegistrar
{
	public:
		BncsMessageFactoryRegistrar(int id, BncsMessage* msg);
};

/* Creates a BncsMessage object based on packet ID. */
class BncsMessageFactory
{
	private:
		static QHash<int, BncsMessage*> msgTable;

	public:
		static BncsMessage* newMessage(int id);

	friend class BncsMessageFactoryRegistrar;
};


#endif /* BNCSMESSAGEFACTORY_H_ */
